package controllers

import (
	"hw_admin/models"
	"hw_admin/enums"
	"github.com/astaxie/beego"
)

type LoginCotroller struct {
	beego.Controller
}

func (this *LoginCotroller) Post()  {
	user := models.AdminUser{}
	username := this.GetString("username")
	password := this.GetString("password")
	user ,err := user.Login(username, password)
	r := &models.JsonResult{enums.JRCodeSucc, "", ""}
	if err != nil {
		r.Code = enums.JRCodeFailed
		r.Msg = "账号密码错误"
	}else {
		vm ,_ := user.GetModels(user.RoleId)
		this.SetSession("adminuser",user)
		this.SetSession("models",vm)
	}
	this.Data["json"] = r
	this.ServeJSON()
	this.StopRun()
}


//登出
func (this *LoginCotroller) Logout ()  {
	this.DelSession("adminuser")
	this.DelSession("models")
	this.TplName = "login.html"
}
